import java.util.concurrent.CountDownLatch;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            int id = i;
            Thread thread = new Thread(()-> {
                System.out.println(id+"线程启动");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(id + "线程结束");
                countDownLatch.countDown();
            });

            thread.start();
        }
        countDownLatch.await();
        System.out.println("所有线程结束");
    }
}
